from sqlalchemy import Column, Integer, String, ForeignKey, JSON
from sqlalchemy.orm import relationship
from ..database import Base

class Node(Base):
    __tablename__ = "nodes"

    id = Column(Integer, primary_key=True, index=True)
    workflow_id = Column(Integer, ForeignKey("workflows.id", ondelete="CASCADE"), nullable=False)
    type = Column(String(50), nullable=False)
    label = Column(String(100))
    params = Column(JSON)
    prev_node_id = Column(Integer, ForeignKey("nodes.id", ondelete="SET NULL"))
    next_node_id = Column(Integer, ForeignKey("nodes.id", ondelete="SET NULL"))

    workflow = relationship("Workflow", back_populates="nodes_rel")
    prev_node = relationship("Node", foreign_keys=[prev_node_id], remote_side=[id])
    next_node = relationship("Node", foreign_keys=[next_node_id], remote_side=[id]) 